package flc.ast.fragment;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import flc.ast.AppConfig;
import flc.ast.R;
import flc.ast.activity.AddDrawActivity;
import flc.ast.activity.DrawRecordActivity;
import flc.ast.activity.TemplateActivity;
import flc.ast.activity.TutorialActivity;
import flc.ast.databinding.FragmentDrawBinding;
import stark.common.api.StkResApi;
import stark.common.base.IReqRetCallback;
import stark.common.basic.base.BaseNoModelFragment;
import stark.common.basic.event.EventStatProxy;
import stark.common.basic.utils.StatusBarUtils;
import stark.common.bean.StkTagResBean;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link DrawFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class DrawFragment extends BaseNoModelFragment<FragmentDrawBinding> {

    private List<StkTagResBean> listTutorial = new ArrayList<>();

    @Override
    protected int onCreate() {
        return R.layout.fragment_draw;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(getActivity(), mDataBinding.event1Container);
        EventStatProxy.getInstance().statEvent5(getActivity(), mDataBinding.event5Container);
        EventStatProxy.getInstance().statEvent5(getActivity(), mDataBinding.event5Container2);

        mDataBinding.ivAddDraw.setOnClickListener(this);
        mDataBinding.ivRecord.setOnClickListener(this);
        mDataBinding.ivTemp1.setOnClickListener(this);
        mDataBinding.ivTemp2.setOnClickListener(this);
        mDataBinding.ivTemp3.setOnClickListener(this);
        mDataBinding.ivTemp4.setOnClickListener(this);
        mDataBinding.ivTemp5.setOnClickListener(this);
        mDataBinding.ivBeginner.setOnClickListener(this);
        mDataBinding.ivHot.setOnClickListener(this);
        mDataBinding.ivLike.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.ivAddDraw://新建画布
                startActivity(AddDrawActivity.class);
                break;
            case R.id.ivRecord://绘画记录
                startActivity(DrawRecordActivity.class);
                break;
            case R.id.ivTemp1://角色
                TemplateActivity.type = 1;
                startActivity(TemplateActivity.class);
                break;
            case R.id.ivTemp2://Q版
                TemplateActivity.type = 2;
                startActivity(TemplateActivity.class);
                break;
            case R.id.ivTemp3://植物
                TemplateActivity.type = 3;
                startActivity(TemplateActivity.class);
                break;
            case R.id.ivTemp4://动物
                TemplateActivity.type = 4;
                startActivity(TemplateActivity.class);
                break;
            case R.id.ivTemp5://其他
                TemplateActivity.type = 5;
                startActivity(TemplateActivity.class);
                break;
            case R.id.ivBeginner://新手推荐
                TutorialActivity.type = 1;
                TutorialActivity.hashId = listTutorial.get(0).getHashid();
                startActivity(TutorialActivity.class);
                break;
            case R.id.ivHot://热门推荐
                TutorialActivity.type = 2;
                TutorialActivity.hashId = listTutorial.get(1).getHashid();
                startActivity(TutorialActivity.class);
                break;
            case R.id.ivLike://猜你喜欢
                TutorialActivity.type = 3;
                TutorialActivity.hashId = listTutorial.get(2).getHashid();
                startActivity(TutorialActivity.class);
                break;
        }
    }

    @Override
    protected void initData() {
        getTutorialData();
    }

    private void getTutorialData() {
        StkResApi.getChildTagList(null, AppConfig.TUTORIAL_DATA, StkResApi.createParamMap(0, 10), false, new IReqRetCallback<List<StkTagResBean>>() {
            @Override
            public void onResult(boolean success, String msg, @Nullable List<StkTagResBean> result) {
                if (success) {
                    if (result != null && result.size() > 0) {
                        listTutorial.addAll(result);
                    }
                }
            }
        });
    }

}